package com.specificgroup.jira.plugin.acpro.util;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;

import java.io.IOException;

/**
 * 
 * @author Ivan Holub
 */
public class HttpUtil {

    public static String post(String url, String request) throws IOException {
        PostMethod post = new PostMethod(url);
        post.setRequestEntity(new StringRequestEntity(request, "text/xml", "UTF-8"));
        post.setRequestHeader("Content-type", "text/xml; charset=UTF-8");
        HttpClient httpclient = new HttpClient();
        try {
            int result = httpclient.executeMethod(post);
            String retValue = post.getResponseBodyAsString();
            return retValue;
        } finally {
            post.releaseConnection();
        }
    }

}
